package com.csg.ses.controller;

import com.csg.ses.common.annotation.LoginToken;
import com.csg.ses.entity.ses.SysRoleRightEntity;
import com.csg.ses.entity.ses.SysRolesEntity;
import com.csg.ses.service.ses.SysRoleRightService;
import com.csg.ses.service.ses.SysRolesService;
import com.csg.ses.vo.common.IdListVo;
import com.csg.ses.vo.common.Result;
import com.csg.ses.vo.common.ResultStatus;
import com.csg.ses.vo.list.RoleRightVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色控制对象
 * @author wangjun
 * @date 2020/11/16
 */
@RestController
@RequestMapping("/role-right")
@Api(tags = "角色权限接口")
public class SysRoleRightController {
    @Autowired
    private SysRoleRightService sysRoleRightService;

    /**
     * 列表
     */
    @ApiOperation(value = "角色控制对象")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "right", value = "角色权限", dataType = "SysRoleRightEntity", paramType = "body"),
        @ApiImplicitParam(name = "current", value = "当前页", required = true ,dataType = "Integer"),
        @ApiImplicitParam(name = "size", value = "每页记录数", required = true ,dataType = "Integer")
    })
    @GetMapping("/list")
    @LoginToken
    public Result<List<SysRoleRightEntity>> list(SysRoleRightEntity right, Long current, Long size) {
        return sysRoleRightService.retrieve(right, current, size);
    }

    /**
     * 删除角色控制对象
     * @param idList
     * @return
     */
    @ApiOperation(value = "删除角色控制对象")
    @ApiImplicitParam(name = "idList", value = "角色控制对象ID数组", dataType = "IdListVo", paramType = "body", required = true)
    @DeleteMapping("/del")
    @LoginToken
    public Result<String> del(@RequestBody IdListVo idList) {
        return new Result(sysRoleRightService.del(idList), ResultStatus.SUCCESS);
    }

    @ApiOperation(value = "根据id查找角色控制对象")
    @ApiImplicitParam(name = "id", value = "角色控制对象id", dataType = "String", required = true)
    @GetMapping("/{id}")
    @LoginToken
    public Result<SysRoleRightEntity> getById(@PathVariable String id) {
        return sysRoleRightService.getById(id);
    }

    /**
     * 保存角色控制对象
     * @param
     * @return
     */
    @ApiOperation(value = "保存角色控制对象")
    @ApiImplicitParam(name = "roleRightVo", value = "角色类型数组", dataType = "RoleRightVo", paramType = "body", required = true)
    @PostMapping("/save")
    @LoginToken
    public Result<String> save(@RequestBody RoleRightVo roleRightVo) {
        return new Result(sysRoleRightService.save(roleRightVo), ResultStatus.SUCCESS);
    }


}